<?php


namespace app\api\controller\v1;


use app\api\model\Product;
use app\api\validate\Count;
use app\api\validate\IDMustBePostivelnt;
use app\lib\exception\recentException;

class ProductController{
    //获取指定数量的商品数据
    //$count 1,10之间，必须存在
    public function getRecent($count=16){
        (new Count())->goCheck();
        $productModel = new Product();
        $list = $productModel::getMostRecent($count);
        if($list->isEmpty()){
            throw new recentException();
        }
        return json($list);
    }


    //获取商品详情
    public function getProductDetails($id){
        (new IDMustBePostivelnt())->goCheck();
        $productModel = new Product();
        $list = $productModel::getOneProductDetails($id);
        return json($list);
    }

    //获取分类下的商品
    public function getProductByCategory($id){
        (new IDMustBePostivelnt())->goCheck();
        $productModel = new Product();
        $list = $productModel::getAllProductByCategory($id);
        return $list;
    }



}





